<%@page import="java.awt.print.Printable"%>
<%@ page contentType="text/html;charset=UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ taglib prefix="tags" tagdir="/WEB-INF/tags"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />

<html>
<head>
<title>优先派送查询</title>
<script type="text/javascript">
    var datatable_content;
	var filterParam = {};

    $(function() {
		$("#alreadyMyCheckedAll").iCheck({
			checkboxClass : 'icheckbox_minimal'
		});
		$("#alreadyMyCheckedAll").on("ifChecked", function(event) {
			$("input[name='alreadyMyChecked'").iCheck('check');
		});
		$("#alreadyMyCheckedAll").on("ifUnchecked", function(event) {
			$("input[name='alreadyMyChecked'").iCheck('uncheck');
		});
	});
    
	function initTable() {
		datatable_content = $("#contentTable").dataTable(
						{
							"bServerSide" : true,
							"bAutoWidth" : false,
							"sAjaxSource" : '${ctx}/prioritySend/v2_queryOrder',
							"fnServerData" : callback,
							"fnRowCallback" : rowCallBack,
							//"sScrollX":"120%",
							"bFilter" : false,
							"bSort" : false,
							"sZeroRecords" : "查询无记录！",
							"bProcessing" : true,
							"iDisplayLength" : 10,//单页显示的数据的条数
							"oLanguage" : {
								"sUrl" : '${ctx}/static/v2/js/plugins/datatables/cn.txt'
							},
							"aoColumns" : [
									{
										"mData" : null,
										"mRender" : function(data, display, row) {
											var str = "<input type=\"checkbox\" name=\"alreadyMyChecked\" id=\"check_already"+row.orderType+"_"+row.ordeno+"\" value="+row.orderType+"_"+row.ordeno+"  />";
											return str;
										}
									},
									{
										"mData" : null,
									},
									{
										"mData" : "orderType"
									},
									{
										"mData" : 'ordeno'
									},
									{
										"mData" : 'mailNo'
									},
									{
										"mData" : 'sendna'
									},
									{
										"mData" : 'sendProvna'
									},
									{
										"mData" : 'sendCityna'
									},
									{
										"mData" : 'sendAddres'
									},
									{
										"mData" : 'sendMobile'
									},
									{
										"mData" : 'sendTeleph'
									},
									{
										"mData" : 'recena'
									},
									{
										"mData" : 'provna'
									},
									{
										"mData" : 'cityna'
									},
									{
										"mData" : 'addres'
									},
									{
										"mData" : 'mobile'
									},
									{
										"mData" : 'teleph'
									},
									{
										"mData" : 'returnStatus'
									}									
									 ]
						});
	}
	function filter(item) {
		filterParam[item.name] = item;
	}
	function callback(sSource, aoData, fnCallback) {
		//查询参数
		var orderType = $("#_orderSource").val();
		aoData.push({
			"name" : "orderType",
			"value" : orderType
		});
	
		var returnsStatus = $("#_returnsStatus").val();
		aoData.push({
			"name" : "returnsStatus",
			"value" : returnsStatus
		})
		$.ajax({
			"type" : "post",
			//"contentType" : "application/json",
			"url" : sSource,
			"dataType" : "json",
			"data" : arrayToJson(aoData),
			"success" : function(resp) {
				fnCallback(resp);
			}
		});
	}
	/**
	 *创建了行的回调
	 *nRow为当前的tr
	 */
	function rowCallBack(nRow, aData, iDisplayIndex, iDisplayIndexFull) {
		var iDisplayStart = datatable_content.fnSettings()._iDisplayStart;
		$("td:eq(1)", nRow).html(iDisplayStart + iDisplayIndex + 1);
	}
	
	 /**
     *	将json数组转换为json对象
     */
     function arrayToJson(array) {
     	var jsonParam = {};
         for (var i = 0; i < array.length; i++) {
         	jsonParam[array[i].name] = array[i].value;
       	}
       	return jsonParam;
   	}
	 
	function load() {
		if (datatable_content) {
			datatable_content.fnDestroy();
		}
		initTable();
	}
	
	function getCheckedList() {
		var tempChecked = [];
		$("input[type='checkbox'][name='alreadyMyChecked']:checked").each(
				function(i) {
					tempChecked.push($(this).val());
				});
		return tempChecked;
	}
	/**
	*批量重新回传
	*/
	function batchAgainBack() {
		var  ids = getCheckedList();
		var len = ids.length;
		if (len > 100) {
			jAlert("选中的数量大于100", "错误提示");
			return false;
		}
		if (len == 0) {
			jAlert("请选择记录!", "错误提示");
			return false;
		}
		
		if (confirm('是否批量重接回传!')) {
			showBg();
			$.ajax({
				type : 'post',
				url : '${ctx}/prioritySend/batchAgainBack',
				data : 'ids=' + ids ,
				dataType : 'json',
				timeout : 240000,
				success : function(data) {
					closeBg();
					if (data.status == "1") {
						datatable_content.fnDraw();
						alert(data.msg);
					} else {
						alert(data.msg);
					}
				},
				error : function() {
					closeBg();
					alert("服务器异常，请重试");
				},

			});
		}
	}
	
	
	
	
	
</script>


</head>

<body>

<div id="fullbg"></div>
	<div id="dialog">
		<div>
			<img src="${ctx }/static/022.gif"></img>
		</div>
	</div>
<section class="content">
		<div class="row">
			<div class="col-md-12">

				<!-- Primary box -->
				<div class="box box-solid box-primary">
					<div class="box-header">
						<i class="fa fa-edit"></i>
						<h3 class="box-title">条件查询</h3>
						<div class="box-tools pull-right">
							<button class="btn btn-primary btn-sm" data-widget="collapse">
								<i class="fa fa-minus"></i>
							</button>
						</div>
					</div>
					<div class="box-body">


						<form class="form-search" id="queryForm" style="margin-top: 10px;">

							<div class="form-group row">

								<div class="col-sm-3">
									<div class="input-group col-sm-12">
										<span class="input-group-text"> 订单来源: </span> 
										<select data-placeholder="请选择..." class="form-control searchSelect" id="_orderSource" name="_orderSource" value="${param._orderSource}">
											<option value="">全部</option>
											<option value="系统订单">系统订单</option>
											<option value="导入订单">导入订单</option>
										</select>
									</div>
								</div>

								<div class="col-sm-3">
									<div class="input-group col-sm-12">
										<span class="input-group-text"> 回传状态: </span> <select
											class="form-control" id="_returnsStatus" name="_returnsStatus" value="${param._returnsStatus}">
											<option value="">全部</option>
											<option value="fail">失败</option>
											<option value="success">成功</option>
											<!-- <option value="失败">失败</option>
											<option value="成功">成功</option>  -->
										</select>
									</div>
								</div>

								<div class="col-sm-2">
									<div class="input-group col-sm-12">
                                        <button class="btn btn-primary" type="button" onclick="load();">搜索</button>	
                                        <a href='#inputFile'  class='btn btn-primary' role='button' data-toggle='modal' >导入订单</a>								
                                    </div>
								</div>

							</div>
						</form>

					</div>
				</div>
			</div>
		</div>




		<!-- 查询结果 start -->
		<div class="form-group row">
		<div class="col-md-12">
			<div class="box box-solid box-primary">
				<div class="box-header">
					<i class="fa fa-list"></i>
					<h3 class="box-title">查询结果</h3>
					<div class="box-tools pull-right">
						<button class="btn btn-primary btn-sm" data-widget="collapse"
							type="button">
							<i class="fa fa-minus"></i>
						</button>
					</div>
				</div>
				<div class="box-body">

						<table id="contentTable"
							class="table table-striped table-bordered table-condensed">
							<thead>
								<button class="btn btn-primary" type="button" onclick="batchAgainBack();">批量重接回传</button>
								<tr>
									<th style="width: 30px;"><input type="checkbox" name="alreadyMyCheckedAll" id="alreadyMyCheckedAll" onclick="alreadyMyCheckedAll()" /></th>
									<th>序号</th>
									<th>订单来源</th>
									<th>订单号</th>
									<th>快递单号</th>
									<th>寄件人姓名</th>
									<th>寄件人省份</th>
									<th>寄件人城市</th>
									<th>寄件人地址</th>
									<th>寄件人手机</th>
									<th>寄件人电话</th>
									<th>收件人姓名</th>
									<th>收件人省份</th>
									<th>收件人城市</th>
									<th>收件人地址</th>
									<th>收件人手机</th>
									<th>收件人电话</th>
									<th>上传状态</th>
								</tr>
							</thead>
							<tbody>
						    </tbody>
					</table>
				</div>
			</div>
		</div>
	</div>

     <!-- 弹出窗体-导入线下订单 start  -->
	<div id="inputFile" class="modal fade">
		<div class="modal-dialog" style="width: 60%;">
			<div class="modal-content">
				<div class="modal-body">
					<div class="box box-solid box-primary">
			      		<div class="box-header"><span class="box-title">导入订单</span></div>
						<div class="box-body">
							<form id="form1"  method="post" enctype="multipart/form-data">
								<table class="table table-striped table-bordered table-condensed">
									<tbody>
										<tr>
											<td>
												<input name="file" class="btn" type="file">
											</td>
										</tr>
										<tr>
											<td style="height: 50px; vertical-align: middle;">
												<input id="submit_btn" class="btn btn-primary" type="submit" value="提交" />
												<button type="reset" class="btn">
													重置
												</button>
											</td>
										</tr>
								  </tbody>
							   </table>
						   </form>
						</div>
					</div>
				</div>
				
			</div>	
		</div>
	</div>
	<script type="text/javascript">
		$("#submit_btn").click(
				function() {
					showBg();
					$("#form1").attr("action", "${ctx}/prioritySend/v2_importExcel");
		});
	</script>
	</section>
		
</body>
</html>
